package com.yuexun.dhdoctor.module.meetingMaterial.presenter.impl;

import com.yuexun.dhdoctor.module.meetingMaterial.bean.MeetingMaterialListBean;
import com.yuexun.dhdoctor.module.meetingMaterial.model.IMeetingMaterialModel;
import com.yuexun.dhdoctor.module.meetingMaterial.presenter.IMeetingMaterialPresenter;
import com.yuexun.dhdoctor.module.meetingMaterial.ui.IMeetingMaterialView;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Func1;
import rx.schedulers.Schedulers;

/**
 * Created by Administrator on 2016/11/15.
 */
public class MeetingMaterialPresenter implements IMeetingMaterialPresenter {

    IMeetingMaterialView mView;
    IMeetingMaterialModel mModel;

    public MeetingMaterialPresenter(IMeetingMaterialView view, IMeetingMaterialModel model){
        this.mView=view;
        this.mModel=model;
    }

    @Override
    public void showMeetingMaterialList(String sessionUuid, String title, String startDate, String endDate, int pageSize, int pageIndex, boolean adminFlag) {
        mModel.getMeetingMaterialList(sessionUuid, title, startDate, endDate, pageSize, pageIndex, adminFlag)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .filter(new Func1<MeetingMaterialListBean, Boolean>() {
                    @Override
                    public Boolean call(MeetingMaterialListBean meetingMaterialListBean) {
                        return Integer.parseInt(meetingMaterialListBean.getStatus())==200;
                    }
                })
                .subscribe(new Subscriber<MeetingMaterialListBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(MeetingMaterialListBean meetingMaterialListBean) {
                        mView.showMeetingMaterialList(meetingMaterialListBean.getDatas());
                    }
                });
    }
}
